package parser

import (
	"regexp"

	"gitee.com/wuzp__dev/crawler/crawler/engine"
	"gitee.com/wuzp__dev/crawler/crawler_distributed/config"
)

// 这里要注意下[^<]的写法，表示匹配非<的字符，遇到<后就停止匹配
var cityListRe = regexp.MustCompile(
	`<a href="(http://www.zhenai.com/zhenghun/[0-9a-z]+)"[^<]*>([^<]+)</a>`)

func ParseCityList(contents []byte, _ string) engine.ParseResult {
	matches := cityListRe.FindAllSubmatch(contents, -1)

	result := engine.ParseResult{}
	for _, m := range matches {
		// result.Items = append(result.Items, "City "+string(m[2]))
		result.Requests = append(result.Requests, engine.Request{
			Url:    string(m[1]),
			Parser: engine.NewFuncParser(ParseCity, config.ParseCity),
		})
	}
	return result
}
